package day18;

import java.util.concurrent.locks.ReentrantLock;

public class Three {
    ReentrantLock lock=new ReentrantLock(true);
    public void print(){
        String name=Thread.currentThread().getName();
        for (int i=0;i<5;i++){
            lock.lock();
            try {
                Thread.sleep(1000);
                System.out.print(name);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        Three three=new Three();
        new Thread(()->{
            three.print();
                },"A").start();
        new Thread(()->{
            three.print();
            },"B").start();
        new Thread(()->{
            three.print();
            },"C").start();
    }
}
